<?php

namespace app\personal\controller;

use think\Controller;
use think\Request;
use think\Db;

class Follow extends Controller
{
    /**
     *   初始化
     *  判断是否登陆
     */
    public function _initialize()
    {
        if (session('tel') == null){
            return $this->error('您还未登陆,请先登陆!');
        }
    }

    /**
     * 显示关注列表
     * @return \think\Response
     */
    public function index()
    {
        $follow = Db::table(['follow', 'user_self'])
            ->field('follow.id,user_self.nickname,user_self.icon,follow.buid')
            ->where('user_self.uid=follow.buid and follow.uid='.session('uid'))
            ->select();
//        dump($follow);
        $ass = Db::name('subscribe s')
            ->join('column c','s.cid = c.cid')
            ->where('s.uid ='.session('uid'))
            ->limit(9)
            ->select();
        $user = Db::table('user_self')->field('nickname,icon')->where('uid ='.session('uid'))->find();
        return view('Follow/index', [
            'title' => '【众评网】为你私人定制的资讯客户端 --- 【che-cn.com】 - 个人中心',
            'follow' => $follow,
            'ass' => $ass,
            'user' => $user,
        ]);
    }

    /**
     * 显示创建资源表单页.
     *
     * @return \think\Response
     */
    public function create()
    {
        //
    }

    /**
     * 保存新建的资源
     *
     * @param  \think\Request  $request
     * @return \think\Response
     */
    public function save(Request $request)
    {
        //
    }

    /**
     * 显示指定的资源
     *
     * @param  int  $id
     * @return \think\Response
     */
    public function read($id)
    {
        //
    }

    /**
     * 显示编辑资源表单页.
     *
     * @param  int  $id
     * @return \think\Response
     */
    public function edit($id)
    {
        //
    }

    /**
     * 保存更新的资源
     *
     * @param  \think\Request  $request
     * @param  int  $id
     * @return \think\Response
     */
    public function update(Request $request, $id)
    {
        //
    }

    /**
     * 删除指定资源
     *
     * @param  int  $id follow id
     * @return \think\Response
     */
    public function delete($id)
    {
        $result = Db::table('follow')->where('uid ='.session('uid'))->delete($id);
        return json($result);
    }
}
